package com.lly.bigdata.bgayx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lly.bigdata.bgayx.entity.SysUserRole;
import com.lly.bigdata.bgayx.mapper.SysUserRoleMapper;
import com.lly.bigdata.bgayx.service.ISysUserRoleService;
import com.lly.bigdata.bgayx.vo.Result;
import com.lly.bigdata.bgayx.vo.SearchModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户与角色对应关系 服务实现类
 * </p>
 *
 * @author lly
 * @since 2020-10-21
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    @Override
    public Result queryPage(SearchModel searchModel) {
        IPage page = new Page(searchModel.getPage(), searchModel.getRows());
        QueryWrapper queryWrapper = new QueryWrapper();
        if (StringUtils.isNotBlank(searchModel.getS_name())) {
            queryWrapper.like("role_name", "%" + searchModel.getS_name() + "%");
        }
        IPage pages = baseMapper.selectPage(page, queryWrapper);
        Result res = Result.pageOk(pages.getRecords());
        res.setTotal(pages.getTotal());
        return res;
    }

}
